﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TemplateMethodPattern
{
    /// <summary>
    /// 银行客户端
    /// </summary>
    public abstract class Client
    {
        /// <summary>
        /// 查询余额
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        public void QueryBalance(string userName, string password)
        {
            //检查账号
            //查询余额
            //查询利息
            //展示
            int id = 0;
            if (CheckUser(userName, password, out id))
            {
                if (IsSecret(id))
                {
                    Console.WriteLine("这个是保密账户，不能查询");
                    return;
                }
                double amount = GetAmount(id);
                double interrest = GetInterest(amount);
                Show(userName, amount, interrest);
            }
            else
            {
                Console.WriteLine("账户密码错误");
            }
        }

        public virtual bool IsSecret(int userId)
        {
            return false;
        }

        private bool CheckUser(string userName, string password, out int id)
        {
            id = new Random().Next(11111111, 99999999);
            return DateTime.Now < DateTime.Now.AddHours(1);
        }

        private double GetAmount(int userId)
        {
            return new Random().Next(10000, 1000000);
        }

        public abstract double GetInterest(double amount);

        //public abstract void Show(string userName, double amount, double interrest);
        ////{
        ////    Console.WriteLine("尊敬的{0}客户，您的余额为{1},利息为{2},总金额为{3}", userName, amount, interrest, amount + interrest);
        ////}
        public virtual void Show(string userName, double amount, double interrest)
        {
            Console.WriteLine("尊敬的{0}客户，您的余额为{1},利息为{2},总金额为{3}", userName, amount, interrest, amount + interrest);
        }

    }
}
